package com.itheima.web.converters;

import com.itheima.common.utils.UtilFuns;
import org.springframework.core.convert.converter.Converter;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 自定义类型转换器
 */
public class StringToDateConverters implements Converter<String, Date> {
    private String pattem;

    public StringToDateConverters(String pattem) {
        this.pattem = pattem;
    }

    public StringToDateConverters() {
    }

    @Override
    public Date convert(String entryParameter) {
        if (UtilFuns.isNotEmpty(pattem)) {
            throw new RuntimeException("对不起数据源为空");
        }
        try {
            return new SimpleDateFormat("yyyy-MM-dd").parse(entryParameter);//转换
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }
}
